WPP:RegisterAction("NOCLIP", "NoClip", "Ghost though entitys with noclip.");

WPP:SetWorldAcess(WPP_NOCLIP, true)

hook.Add( "Move", "WPP-CanClip",function(Player,Move)
	if ( Player:GetMoveType() ~= MOVETYPE_NOCLIP ) then
		return;
	end
	
	if ( GetConVarNumber("wpp_anti_noclip") == 0 ) then
		return;
	end
	
	local Velocity = Move:GetVelocity();
	local Frame = FrameTime();
	Velocity = Velocity + Player:EyeAngles():Forward() * Move:GetForwardSpeed() / 4 * Frame;
	Velocity = Velocity + Player:EyeAngles():Right() * Move:GetSideSpeed() / 4 * Frame;
	Velocity = Velocity + Player:EyeAngles():Up() * Move:GetUpSpeed() / 3 * Frame;
	if ( Velocity == Vector( 0, 0, 0 ) ) then
		return;
	end
	
	local Normal = Velocity:GetNormalized();
	if Velocity == Vector( 0, 0, 0 ) then
		return;
	end
	
	local TraceData = {};
	TraceData.start = Player:GetPos();
	TraceData.endpos = Player:GetPos() + Velocity * Frame + Normal;
	TraceData.filter = { Player };
	Trace = util.TraceEntity( TraceData, Player );
	
	local CanClip = true;
	local Hits = {};
	while Trace.Hit do
	
		if ( Trace.HitWorld ) then
			break; //No props outside of world
		elseif ( Trace.Entity ) then
			if ( Trace.Entity:IsValid() ) and ( WPP:IsOwned(Trace.Entity) ) then
				table.insert(Hits,Trace.Entity);
			end
		
			table.insert(TraceData.filter,Trace.Entity); //Add this to the trace filter
		else
			break;
		end
		
		Trace = util.TraceEntity( TraceData, Player );
		
	end
	
	for _,Entity in pairs (Hits) do
		if ( WPP:IsOwned(Entity) ) then
			if ( !WPP:ValidateAction(WPP_NOCLIP,Entity,Player) ) then
				CanClip = false;
				break; //They cant move though this so no point doing anything else
			end
			
		end
		
	end
	
	if ( !CanClip ) then
		Move:SetVelocity( Vector( 0, 0, 0 ) );
		Move:SetForwardSpeed( Move:GetForwardSpeed() * -1 );
		Move:SetSideSpeed( Move:GetSideSpeed() * -1 );
		Move:SetUpSpeed( Move:GetUpSpeed() * -1 );
	end
	
end)



